package com.example.user1.vo;
import com.example.user1.enums.ErrorEnum;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class Result<T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> Result<T> success() {
        return new Result<>(0, "");
    }
    public static <T> Result<T> success(T data) {
        return new Result<>(0, "", data);
    }

    public static <T> Result<T> failed(String message) {
        //todo 此处可国际化
        return new Result<>(1, message);
    }

    public static <T> Result<T> failed(ErrorEnum errorEnum) {
        //todo 此处可国际化
        return new Result<>(1, errorEnum.getMessage());
    }
}
